<template>
	<view class="page-transfer">
		<view class="condition">
			<view class="conmenus">
				<view class="conleft">{{$t('defect.defInfo.turnDfLevelNo')}}<span class="redx">*</span></view>
				<view class="conright">
					<data-picker v-model="level" :range="levelOptions"></data-picker>
				</view>
			</view>
			<view class="conmenus">
				<view class="conleft">{{$t('defect.defInfo.turnTTConesc')}}<span class="redx">*</span></view>
				<view class="conright">
					<input :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" v-model="situation"/>
				</view>
			</view>
			<view class="conmenus">
				<view class="conleft">{{$t('defect.defInfo.turnTTRiskAssess')}}<span class="redx">*</span></view>
				<view class="conright">
					<input :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" v-model="risk"/>
				</view>
			</view>
			<view class="contexts">
				<view class="conleft">{{$t('defect.defInfo.turnTTMeasure')}}<span class="redx">*</span></view>
				<view class="coninputright">
					<textarea :placeholder="$t('baseCommon.message.pleaseEnter', { title: '' })" auto-height v-model="measure"/>
				</view>
			</view>
		</view>
		
		<view class="button-popup">
			<button type="primary" @click="submit">{{$t('baseCommon.buttons.submit')}}</button>
			<button type="default" @click="reset">{{$t('baseCommon.buttons.reset')}}</button>
		</view>
		
	</view>
</template>

<script>
	import { getDefectLevel } from '@/api/business/defect.js'
	import { notice, utilities } from '@/utils/common.js'
	
	export default {
		props: {
			data: {
				type: Object,
				default() {
					return {}
				}
			},
			levelNo: {
				type: String,
				default() {
					return ""
				}
			},
			operationTeamNo: {
				type: String,
				default() {
					return ""
				}
			}
		},
		data() {
			return {
				levelOptions: [],
				formData: this.data,
				level: '',
				situation: '',
				risk: '',
				measure: ''
			}
		},
		created() {
			this.init()
		},
		methods: {
			async init() {
				await getDefectLevel().then(res=>{
					this.levelOptions = []
					const _this = this
					for (const [key, value] of Object.entries(res.data)) {
						_this.levelOptions.push({
							value: key,
							label: value
						})
					}
				})
				if(this.levelNo){
					this.level = this.levelNo
				}
			},
			submit() {
				if(!this.level){
					notice.toast(this.$t('baseCommon.message.pleaseSelect', { title: this.$t('defect.defInfo.turnDfLevelNo') }))
					return
				}
				if(!this.situation){
					notice.toast(this.$t('baseCommon.message.pleaseEnter', { title: this.$t('defect.defInfo.turnTTConesc') }))
					return
				}
				if(!this.risk){
					notice.toast(this.$t('baseCommon.message.pleaseEnter', { title: this.$t('defect.defInfo.turnTTRiskAssess') }))
					return
				}
				if(!this.measure){
					notice.toast(this.$t('baseCommon.message.pleaseEnter', { title: this.$t('defect.defInfo.turnTTMeasure') }))
					return
				}
				
				this.formData.changeDesp = this.situation
				this.formData.applyedMeasure = this.measure
				this.formData.risk = this.risk
				this.formData.toLevel = this.level
				this.formData.changeType = "ylzesl"
				
				let projectType = uni.getStorageSync("projectType")
				if(projectType == "wind") {
					this.$emit("getRecord", this.formData)
					
					let that = this
					uni.navigateTo({
						url: "/pages/base/select-user-multi?type=transfer&groupId="+this.operationTeamNo,
						events: {
							selectUserMulti(data) {
								that.$emit("close", "transfer", data)
							}
						}
					})
				} else if(projectType == "fire") {
					this.formData.changeTime = utilities.getNowDateTime()
					this.$emit("getRecord", this.formData)
					this.$emit("close", "transfer")
				}
			},
			reset() {
				this.level = ""
				this.situation = ""
				this.risk = ""
				this.measure = ""
			}
		}
	}
</script>

<style lang="scss">
	@import '@/static/style/common-detail.scss';
	
	.page-transfer {
		overflow-y: auto;
		background-color: #fff;
		width: 350px;
	}
</style>
